
class Storage {
    set(key, value) {
        const valueStr = JSON.stringify(value)
        uni.setStorageSync(key, valueStr)
    }

    get(key) {
        const value = uni.getStorageSync(key)
        if(value) {
            return JSON.parse(value)
        } else {
            if(key === "userInfo") {
                uni.reLaunch({url: '/pages/login/login'})
            } else {
                throw new Error("没有找到该key")
            }
        }

    }

    remove(key) {
        uni.removeStorageSync(key)
    }
}

export default new Storage()
